import http from '@/utils/request'
import type { DictDataPaginationReq } from '@/api/system/dict'
import { DictAPIs, EnumDictName } from '@/api/system/dict'
import type { KeyValue } from '../common'

/**号类*/
export interface ClinicType {
  clinicType: string
}

/**挂号就诊类型字典 */
export interface ClinicTypeSetting {
  clinicType: string
  chargeItem: string
  priceItem: string
  editStatus: boolean
}

/**就诊类型收费系数字典 */
export interface ClinicTypeCharge {
  clinicType: string
  registType: string
  chargeItem: string
  calcType: string
  calcVal: number
}

/**科室附加费 */
export interface OutpDeptAppendPrice {
  deptCode: string
  deptName: string
  itemCode: string
  price: number
}

/**挂号收费项目 */
export const ChargeItems: KeyValue[] = [
  { key: '挂号费', value: '挂号费' },
  { key: '诊疗费', value: '诊疗费' },
]

/**号签信息 */
export interface ClinicIndex {
  clinicLabel: string
  doctorId: string
  doctorName: string
  deptCode: string
  deptName: string
  clinicType: string
  addr: string
}

/**时间描述 */
export interface TimeInterval {
  timeDesc: string
  beginTime: string
  endTime: string
}

/**号源池(天健) */
export interface RegisterTJPool {
  clinicLabel: string
  timeDesc: string
  clinicDate: Date
}

/**挂号基础数据API */
export const RegisterBaseAPIs = {
  /**号类(分页) */
  getClinicTypeByPagination: (data: DictDataPaginationReq) => {
    data.dictName = EnumDictName.挂号号类
    return DictAPIs.getDataByPagination(data)
  },
  /**获取号类收费项目设置 */
  getClinicTypeSetting: (clinicType: string) => {
    return http.get<ClinicTypeSetting[]>('register/getClinicTypeSetting', { clinicType })
  },
  /** 获取号类收费项目金额计算方式*/
  getClinicTypeCharge: (clinicType: string) => {
    return http.get<ClinicTypeCharge[]>('register/getClinicTypeCharge', { clinicType })
  },
  /**号签(分页) */
  getClinicIndexByPagination: (data: DictDataPaginationReq) => {
    data.dictName = EnumDictName.挂号号签
    return DictAPIs.getDataByPagination(data)
  },
  /**挂号时间描述字典 */
  getTimeInterval: async () => {
    return (
      await DictAPIs.getDataByPagination<TimeInterval>({
        dictName: EnumDictName.挂号时间描述字典,
        isPagination: false,
        queryText: '',
        currentPage: 0,
        pageSize: 0,
      })
    ).data
  },
}
